home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / dev / e / eiffel.lha / flc / docs / string.doc < prev   
Encoding:
Text File  |  1996-01-25  |  4.4 KB  |  161 lines

  1.  
  2. -- Characters strings
  3.  
  4. expanded class interface STRING
  5. creation procedures
  6.   make (n:INTEGER)
  7.     -- Allocate space for at least 'n' characters.
  8.     require
  9.       non_negative_size: n >= 0
  10.     ensure
  11.       capacity = n
  12. exported features
  13.   append (s:STRING)
  14.     -- Append a copy of 's' at end of current string.
  15.     require
  16.       argument_not_void: s /= Void
  17.     ensure
  18.       count = old count + s.count
  19.   capacity:INTEGER
  20.     -- Number of characters that can be contained in the string
  21.   clear
  22.     -- Clear out string.
  23.     ensure
  24.       count = 0
  25.   copy (other:STRING)
  26.     -- Reinitialize with copy of 'other'
  27.     require
  28.       other /= Void
  29.     ensure
  30.       count = other.count;
  31.     -- For all i: 1..count, item (i) = other.item (i)
  32.   count:INTEGER
  33.     -- Actual number of characters making up the string
  34.     ensure
  35.       Result >= 0
  36.   empty:BOOLEAN
  37.     -- Is string empty?
  38.   extend (c:CHARACTER)
  39.     -- Add 'c' at end.
  40.     ensure
  41.       count = old count + 1
  42.   fill_blank
  43.     -- Fill with blanks.
  44.     ensure
  45.     -- For all i: 1..count, item (i) = Blank
  46.   hash_code:INTEGER
  47.     -- Hash code value of current string
  48.   head (n:INTEGER)
  49.     -- Remove all characters except for the first 'n';
  50.     -- do nothing if n >= count.
  51.     require
  52.       non_negative_argument: n >= 0
  53.     ensure
  54.     -- count = min (n,old count)
  55.   index_of (c:CHARACTER; i:INTEGER):INTEGER
  56.     -- Index of the first occurence of 'c', starting at
  57.     -- position i; 0 if not found.
  58.     require
  59.       index_large_enough: i >= 1;
  60.       index_small_enough: i <= count
  61.     ensure
  62.       Result = 0 or item (Result) = c
  63.   is_equal (other:STRING):BOOLEAN
  64.     -- Is current string made of the same characters sequence as 'other'?
  65.     -- (Redefined from 'ANY')
  66.   item (i:INTEGER):CHARACTER
  67.     -- Character at position 'i'
  68.     require
  69.       index_large_enough: i >= 1;
  70.       index_small_enough: i <= count
  71.   item_code (i:INTEGER):INTEGER
  72.     -- Numeric code of character at position 'i'
  73.     require
  74.       index_large_enough: i >= 1;
  75.       index_small_enough: i <= count
  76.   lef_adjust
  77.     -- Remove leading blanks.
  78.     -- NOT IMPLEMENTED.
  79.     ensure
  80.       (count /= 0) implies (item (1) /= ' ')
  81.   precede(c:CHARACTER)
  82.     -- Add 'c' at front.
  83.     -- NOT IMPLEMENTED.
  84.     ensure
  85.       count = old count + 1
  86.   prepend(s:STRING)
  87.     -- Prepend a copy of 's' at front of current string.
  88.     -- NOT IMPLEMENTED.
  89.     require
  90.       argument_not_void: s /= Void
  91.     ensure
  92.       count = old count + s.count
  93.   put (c:CHARACTER; i:INTEGER)
  94.     -- Replace by 'c' character at position 'i'.
  95.     require
  96.       index_large_enough: i >= 1;
  97.       index_small_enough: i <= count
  98.     ensure
  99.       item (i) = c
  100.   remove (i:INTEGER)
  101.     -- Remove i-th character.
  102.     -- NOT IMPLEMENTED.
  103.     require
  104.       index_large_enough: i >= 1;
  105.       index_small_enough: i <= count
  106.     ensure
  107.       count = old count - 1
  108.   remove_all_occurrences (c:CHARACTER)
  109.     -- Remove all occurrences of 'c'.
  110.     -- NOT IMPLEMENTED.
  111.     ensure
  112.     -- For all i: 1..count, item (i) /= c
  113.     -- count = old count - number of occurrences of 'c' in initial string
  114.   right_adjust
  115.     -- Remove trailing blanks.
  116.     -- NOT IMPLEMENTED.
  117.     ensure
  118.       count /= 0 implies item (count) /= ' '
  119.   shrink (s:STRING; n1,n2:INTEGER)
  120.     -- Remove characters outside of interval n1..n2
  121.     -- NOT IMPLEMENTED.
  122.     require
  123.       argument_not_void: s /= Void
  124.       meaningful_origin: 1 <= n1;
  125.       meaningful_interval: n1 <= n2;
  126.       meaningful_end: n2 <= s.count
  127.     ensure
  128.       is_equal (s.substring (n1, n2))
  129.   substring (n1, n2:INTEGER):STRING
  130.     -- Copy of substring of current string containing all characters
  131.     -- at indices between n1 and n2.
  132.     -- NOT IMPLEMENTED.
  133.     require
  134.       meaningful_origin: 1 <= n1;
  135.       meaningful_interval: n1 <= n2;
  136.       meaningful_end: n2 <= count
  137.     ensure
  138.       Result.count = n2 - n1 +1
  139.     -- For all i: 1..n2-n1, Result.item(i) = item (n1 +i -1)
  140.   tail (n:INTEGER)
  141.     -- Remove all characters except for the last 'n';
  142.     -- do nothing if n >= count.
  143.     -- NOT IMPLEMENTED.
  144.     require
  145.       non_negative_argument: n >= 0
  146.     ensure
  147.     -- count = min (n,old count)
  148.   to_integer:INTEGER
  149.     -- Integer value of current string, assumed to contain digits only
  150.     -- When applied to "123", will yield 123.
  151.     require
  152.     -- String contains digits only
  153.   to_lower
  154.     -- Convert string to lower case.
  155.   to_upper
  156.     -- Convert string to upper case.
  157. invariant
  158.    0 <= count; count <= capacity
  159. end interface -- class 'STRING'
  160.  
  161.